package com.rc.saas.tenant.transfers.alipay.config;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
 * 支付宝支付的配置信息,求资金类必须用证书方式加密
 * https://opendocs.alipay.com/open/309/106235
 * Created by Sven on 2021/01/27
 */
@Component
@PropertySource("classpath:alipaycert/alipay.properties")
@ConfigurationProperties(prefix = "alipay")
public class AliPayConfig {
    private static Logger logger = LogManager.getLogger(AliPayConfig.class);

//    @Value("${alipay.appId}")
    private String appId;
    private String privateKey;
    private String publicKey;
//    @Value("${alipay.serverUrl}")
    private String serverUrl;
    private String domain;
    private String format;
    private String charset;
    private String signType;

//    @Value("${alipay.certPath}")
    private String certPath;
//    @Value("${alipay.publicCertPath}")
    private String publicCertPath;
//    @Value("${alipay.rootCertPath}")
    private String rootCertPath;
//    @Value("${alipay.alipayUserId}")
    private String alipayUserId;
    private String alipayUserName;

    /**
     * 加载证书
     * @return
     */
    //public String loadCertContentByPath(String fileName) {
    //    String content = null;
    //    try {
    //        CertificateFactory cf = CertificateFactory.getInstance("X.509");
    //        X509Certificate cert = (X509Certificate) cf.generateCertificate(new FileInputStream(fileName));
    //        PublicKey publicKey = cert.getPublicKey();
    //        BASE64Encoder base64Encoder = new BASE64Encoder();
    //        content = base64Encoder.encode(publicKey.getEncoded());
    //    } catch (FileNotFoundException e) {
    //        e.printStackTrace();
    //    } catch (CertificateException e) {
    //        e.printStackTrace();
    //    }
    //
    //    logger.info("fileName:{},content:{}", fileName, content);
    //    return content;
    //}

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getPrivateKey() {
        return privateKey;
    }

    public void setPrivateKey(String privateKey) {
        this.privateKey = privateKey;
    }

    public String getPublicKey() {
        return publicKey;
    }

    public void setPublicKey(String publicKey) {
        this.publicKey = publicKey;
    }

    public String getServerUrl() {
        return serverUrl;
    }

    public void setServerUrl(String serverUrl) {
        this.serverUrl = serverUrl;
    }

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    public String getFormat() {
        return format;
    }

    public void setFormat(String format) {
        this.format = format;
    }

    public String getCharset() {
        return charset;
    }

    public void setCharset(String charset) {
        this.charset = charset;
    }

    public String getSignType() {
        return signType;
    }

    public void setSignType(String signType) {
        this.signType = signType;
    }

    public String getCertPath() {
        return certPath;
    }

    public void setCertPath(String certPath) {
        this.certPath = certPath;
    }

    public String getPublicCertPath() {
        return publicCertPath;
    }

    public void setPublicCertPath(String publicCertPath) {
        this.publicCertPath = publicCertPath;
    }

    public String getRootCertPath() {
        return rootCertPath;
    }

    public void setRootCertPath(String rootCertPath) {
        this.rootCertPath = rootCertPath;
    }

    public String getAlipayUserId() {
        return alipayUserId;
    }

    public void setAlipayUserId(String alipayUserId) {
        this.alipayUserId = alipayUserId;
    }

    public String getAlipayUserName() {
        return alipayUserName;
    }

    public void setAlipayUserName(String alipayUserName) {
        this.alipayUserName = alipayUserName;
    }
}
